package com.day20.Box;

public class Box {
    private int milk;
    private Boolean state=false;
    public synchronized void put(int milk){
       if(state){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.milk=milk;
        System.out.println("生产者生产了"+milk+"瓶牛奶");
        state=true;
        notifyAll();
    }
    public synchronized void get() {
        if(!state) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("消费者消费了" + milk + "瓶牛奶");
        state = false;
        notifyAll();
    }
}
